<?php

class TorneosVideosAdminController extends \BaseController {

	public function __construct(){
		
		$roles=array(
				'redactor'=>4,
				'admin'=>1,
				'usuario'=>'2',
				'admin.torneos'=>3
		);
		
		//permisos
		$rolesTorneosVideos=array($roles['admin.torneos'],$roles['admin']);
		
		$this->beforeFilter('roles:'.implode($rolesTorneosVideos,'-'));
	}
	
	
	/**
	 * Display a listing of noticiasadmins
	 *
	 * @return Response
	 */
	public function index()
	{
		$videosTorneos = VideoTorneo::all();
		
		return View::make('contents.admin.torneos-videos.index', compact('videosTorneos'));
	}

	/**
	 * Show the form for creating a new noticiasadmin
	 *
	 * @return Response
	 */
	public function create()
	{
		return View::make('contents.admin.torneos-videos.create');
	}

	/**
	 * Store a newly created noticiasadmin in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		$validator = Validator::make($data = Input::all(), VideoTorneo::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}
		
		$videoTorneo = new VideoTorneo();
		$videoTorneo->torneo()->associate(Torneo::find(Input::get('torneo')));
		$videoTorneo->fill($data);
		$videoTorneo->save();
		

		return Redirect::route('admin.torneos-videos.index');
	}

	/**
	 * Display the specified noticiasadmin.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		$videoTorneo = Campo::findOrFail($id);

		return View::make('contents.admin.torneos-videos.show', compact('videoTorneo'));
	}

	/**
	 * Show the form for editing the specified noticiasadmin.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		$videoTorneo = VideoTorneo::find($id);

		return View::make('contents.admin.torneos-videos.edit', compact('videoTorneo'));
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		$videoTorneo = VideoTorneo::findOrFail($id);

		$validator = Validator::make($data = Input::all(), VideoTorneo::$rules);

		if ($validator->fails())
		{
			return Redirect::back()->withErrors($validator)->withInput();
		}
		$videoTorneo->torneo()->associate(Torneo::find(Input::get('torneo')));
		$videoTorneo->update($data);

		return Redirect::route('admin.torneos-videos.index');
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		VideoTorneo::destroy($id);

		return Redirect::route('admin.torneos-videos.index');
	}

}